#include <bits/stdc++.h>

#define ll long long
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
const int INF = 1e9;
using namespace std;
/*思考区

*/
void solve() {
    int n; 
    cin >> n;
    vector<int> ans(2 * n + 1, 0);
    vector<bool> has(2 * n + 1, 0);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            int x; cin >> x;
            ans[i + j] = x;
            has[x] = true;
        }
    }
    for (int i = 1; i <= 2 * n; i++) {
        if (has[i] == 0) {
            ans[1] = i;
            break;
        }
    }
    for (int i = 1; i <= 2*n; i++) {
        cout << ans[i] << ' ';
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 0;
    cin >> t;
    while (t--)
        solve();
    return 0;
}